package com.nian.images.controller;

import com.nian.common.model.ServerResponse;
import com.nian.images.model.ImagesApp;
import com.nian.images.service.IImagesAppService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 图片信息表 前端控制器
 * </p>
 *
 * @author zhangmj
 * @since 2020-03-31
 */
@RestController
@RequestMapping("/images")
public class ImagesAppImpl {

    @Autowired
    private IImagesAppService iImagesAppService;

    @GetMapping("getUrls/{imagesType}/{imagesIds}")
    public ServerResponse<List<ImagesApp>> getUrl(@PathVariable Integer imagesType, @PathVariable String imagesIds){
        List<ImagesApp> list = iImagesAppService.lambdaQuery().select(ImagesApp::getImagesId,ImagesApp::getImagesUrl)
                .in(ImagesApp::getImagesId, imagesIds.split(",")).eq(ImagesApp::getImagesType, imagesType).list();
        return ServerResponse.createBySuccess(list);
    }

    @GetMapping("getUrl/{imagesType}/{imagesId}")
    public ServerResponse<ImagesApp> getUrl(@PathVariable Integer imagesType, @PathVariable Long imagesId){
        ImagesApp info = iImagesAppService.lambdaQuery().select(ImagesApp::getImagesId,ImagesApp::getImagesUrl)
                .eq(ImagesApp::getImagesId, imagesId).eq(ImagesApp::getImagesType, imagesType).one();
        return ServerResponse.createBySuccess(info);
    }

    @GetMapping("getImage/{imagesType}/{imagesId}")
    public ImagesApp getImage(@PathVariable Integer imagesType, @PathVariable Long imagesId){
        return iImagesAppService.lambdaQuery().select(ImagesApp::getImagesId,ImagesApp::getImagesUrl).one();
    }

    @GetMapping("list/{imagesType}/{imagesIds}")
    public List<ImagesApp> list(@PathVariable Integer imagesType, @PathVariable String imagesIds){
        return iImagesAppService.lambdaQuery().select(ImagesApp::getImagesId,ImagesApp::getImagesUrl).in(ImagesApp::getImagesId, imagesIds.split(",")).eq(ImagesApp::getImagesType, imagesType).list();
    }
}

